package com.shiroha.common.pojo.dto;

import com.shiroha.common.enums.PrivacyOptions;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class PrivacyAttributes {
    private PrivacyOptions work;
    private PrivacyOptions follow;
    private PrivacyOptions like;
    private PrivacyOptions favorite;

    public Map<String, List<String>> toMap() {
        Map<String, List<String>> attributes = new HashMap<>();
        attributes.put("work", List.of(work.getValue()));
        attributes.put("follow", List.of(follow.getValue()));
        attributes.put("like", List.of(like.getValue()));
        attributes.put("favorite", List.of(favorite.getValue()));
        return attributes;
    }

    public static PrivacyAttributes fromMap(Map<String, List<String>> attributes) {
        return PrivacyAttributes.builder()
                .work(PrivacyOptions.valueOf(attributes.get("work").getFirst()))
                .follow(PrivacyOptions.valueOf(attributes.get("follow").getFirst()))
                .like(PrivacyOptions.valueOf(attributes.get("like").getFirst()))
                .favorite(PrivacyOptions.valueOf(attributes.get("favorite").getFirst()))
                .build();
    }
}
